package com.xuecheng.managecms.controller;

import com.xuecheng.framework.web.BaseController;
import com.xuecheng.managecms.service.CmsPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author jl
 * @description
 * @date 2019-08-19 10:38
 */
@Controller
@RequestMapping("/cms")
public class CmsPagePreviewController extends BaseController {
    @Autowired
    private CmsPageService cmsPageService;

    /**
     * 页面预览
     */
    @GetMapping("/preview/{pageId}")
    public void preview(@PathVariable("pageId") String pageId) throws IOException {
        //执行静态化
        String pageHtml = cmsPageService.getPageHtml(pageId);
        //通过response对象将内容输出
        ServletOutputStream outputStream = response.getOutputStream();
        response.setHeader("Content‐type","text/html;charset=utf‐8");
        outputStream.write(pageHtml.getBytes(StandardCharsets.UTF_8));
    }
}
